<template>
  <div class="app-container">
    <el-form ref="From" :model="temp" :rules="rules" label-position="top">
      <el-row :gutter="10">
        <el-col :span="8">
          <el-form-item label="网站名称" prop="siteName">
            <el-input v-model.trim="temp.siteName"/>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="网站url" prop="siteUrl">
            <el-input v-model.trim="temp.siteUrl"/>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="开发团队" prop="developmentTeam">
            <el-input v-model.trim="temp.developmentTeam"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="10">
        <el-col :span="8">
          <el-form-item label="网站url" prop="siteUrl">
            <el-input v-model.trim="temp.siteUrl"/>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="联系地址" prop="address">
            <el-input v-model.trim="temp.address"/>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="联系电话" prop="phone">
            <el-input v-model.trim.number="temp.phone"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="10">
        <el-col :span="8">
          <el-form-item label="传真号" prop="fax">
            <el-input v-model.trim="temp.fax"/>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="邮编" prop="zipCode">
            <el-input v-model.trim.number="temp.zipCode"/>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="邮箱" prop="email">
            <el-input v-model.trim="temp.email"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="10">
        <el-col :span="8">
          <el-form-item label="备案编号" prop="icp">
            <el-input v-model.trim="temp.fax"/>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="是否网站开启" prop="isSiteEnabled">
            <el-checkbox v-model="temp.isSiteEnabled"/>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="网站关闭消息" prop="siteCloseMessage">
            <el-input v-model.trim="temp.siteCloseMessage"/>
          </el-form-item>
        </el-col>
      </el-row>

    </el-form>
  </div>
</template>

<script>
export default {
  name: 'BaseSet',
  props: {
    systemData: {
      type: Object,
      default: function() {
        return {}
      }
    }
  },
  data() {
    var checkPhone = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入'))
      } else {
        if (this.Util.checkMobile(value)) {
          callback()
        } else {
          callback(new Error('请输入正确的号码'))
        }
      }
    }
    var checkEmail = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入'))
      } else {
        if (this.Util.checkEmail(value)) {
          callback()
        } else {
          callback(new Error('请输入正确的邮箱'))
        }
      }
    }
    return {
      temp: {
        siteName: '',
        siteUrl: '',
        developmentTeam: '',
        logo: '',
        indexMainPicture: '',
        address: '',
        phone: '',
        fax: '',
        zipCode: '',
        email: '',
        icp: '',
        isSiteEnabled: false,
        siteCloseMessage: ''
      },
      rules: {
        siteName: [
          { required: true, message: '请输入', trigger: 'blur' }
        ],
        siteUrl: [
          { required: true, message: '请输入', trigger: 'blur' }
        ],
        developmentTeam: [
          { required: true, message: '请输入', trigger: 'blur' }
        ],
        logo: [
          { required: true, message: '请输入', trigger: 'blur' }
        ],
        indexMainPicture: [
          { required: true, message: '请输入', trigger: 'blur' }
        ],
        address: [
          { required: true, message: '请输入', trigger: 'blur' }
        ],
        phone: [
          { required: true, validator: checkPhone, trigger: 'blur' }
        ],
        fax: [
          { required: true, message: '请输入', trigger: 'blur' }
        ],
        zipCode: [
          { required: true, message: '请输入', trigger: 'blur' }
        ],
        email: [
          { required: true, validator: checkEmail, trigger: 'blur' }
        ],
        icp: [
          { required: true, message: '请输入', trigger: 'blur' }
        ],
        siteCloseMessage: [
          { required: true, message: '请输入', trigger: 'blur' }
        ]
      }
    }
  },
  watch: {
    systemData() {
      this.copyTemp()
    }
  },
  created() {
    // this.copyTemp()
  },
  methods: {
    // 初始化数据
    copyTemp() {
      for (var key in this.temp) {
        this.temp[key] = this.systemData[key]
      }
    },

    // 表单验证
    verifyData() {
      var v = false
      this.$refs['From'].validate((valid) => {
        v = valid
      })
      return v
    },

    // 验证通过后 调用此方法 返回数据
    returnData() {
      return this.temp
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>

</style>
